/**
 * 
 */
package com.music.common.service.impl;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.dao.DataAccessException;

import com.music.common.dao.IUserDetails;
import com.music.common.entity.UserDetail;
import com.music.common.errorhandler.DaoException;
import com.music.common.errorhandler.MemusicException;
import com.music.common.service.ILoginService;
import com.music.common.service.ServiceFinder;

/**
 * @author rpatil
 * 
 */
public class LoginService implements ILoginService {

	/*IUserDetails userDetails;

	public LoginService(IUserDetails userDetails) {
		this.userDetails = userDetails;
	}*/
	public LoginService() {
	}

	/**
	 * @param userName
	 * @param password
	 * @return
	 * @throws DataAccessException
	 * @throws java.sql.SQLException
	 */
	public boolean authenticate(String userName, String password, HttpServletRequest request) {
		IUserDetails userDetails = (IUserDetails) ServiceFinder.getContext(request).getBean("SpringHibernateDao");
		try {
			return  userDetails.checkUserLogin(userName, password);
		} catch (DaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	};
	
	/**
	 * @param userName
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	public UserDetail getUserDetails(String userName, HttpServletRequest request) throws Exception {
		IUserDetails userDetails = (IUserDetails) ServiceFinder.getContext(request).getBean("SpringHibernateDao");
		try {
			return userDetails.getUserDetail(userName);
		}catch (Exception ex){
			throw new MemusicException(ex);
		}
	};
}
